package com.tj.test.sys.controller;

import com.tj.test.sys.po.Rolerpower;
import com.tj.test.sys.service.impl.RolerpowerService;
import com.tj.test.sys.tool.ResponseMessage;
import com.tj.test.sys.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("/Rolerpower")
@Api(tags = "Rolerpower")
public class RolerpowerController {
    @Autowired
    private RolerpowerService service;

    @ApiOperation("查询所有角色权限信息")
    @RequestMapping(value = "/selectAllRolerpower",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage selectAllRolerpower(){
        Map<String,List<Rolerpower>> map=new HashMap<>();
        List<Rolerpower> list=service.selectAllRolerpower();
        if (!list.isEmpty()){
            map.put("AllRolerpower",list);
            return Result.success("查询成功",map);
        }
        return Result.error("查询失败",false);
    }

    @ApiOperation("插入角色权限信息")
    @RequestMapping(value = "/insertRolerpower",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage insertRolerpower(Rolerpower rolerpower){
        int temp=0;
        if (rolerpower!=null){
            if (rolerpower.getPrpid()!=0){
                temp=service.insertRolerpower(rolerpower);
                if (temp>0) {return Result.success("插入角色权限信息成功",temp);}
                else  {return Result.error("该角色权限已存在",temp);}
            }
        }
        return Result.error("插入角色权限信息失败",temp);
    }

    @ApiOperation("删除角色权限信息")
    @RequestMapping(value = "/deleteRolerpower",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage deleteRolerpower(Rolerpower rolerpower){
        int temp=0;
        if (rolerpower!=null){
            if (rolerpower.getPrpid()!=0){
                temp=service.deleteRolerpower(rolerpower);
                if (temp>0) {return Result.success("删除角色权限信息成功",temp);}
                else {return Result.error("无该角色权限",temp);}
            }
        }
        return Result.error("删除角色权限信息失败",temp);
    }

    @ApiOperation("修改角色权限信息")
    @RequestMapping(value = "/updateRolerpower",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage updateRolerpower(Rolerpower rolerpower){
        int temp=0;
        if (rolerpower!=null){
            if (rolerpower.getPrpid()!=0){
                temp=service.updateRolerpower(rolerpower);
                if (temp>0) {return Result.success("更新角色权限信息成功",temp);}
                else {return Result.error("无该角色权限信息",temp);}
            }
        }
        return Result.error("更新角色权限信息失败",temp);
    }
}
